/*
 * ResearchGrantsView.java
 */

package researchgrants;

import java.awt.Window;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import researchgrants.parts.GrantRequest.AllGrantRequests;
import researchgrants.parts.GrantRequest.GrantRequestsList;
import researchgrants.parts.GrantRequest.filters.GrantRequestsListFilters;
import researchgrants.parts.GrantRequest.grantOfficer.GrantOfficer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import researchgrants.parts.GrantRequest.grantOfficer.LoggedDataPanelsListGrantOfficer;
import researchgrants.parts.pi.AllPis;
import researchgrants.parts.pi.PisList;
import researchgrants.personalize.PropertyFile;
import researchgrants.utils.MyDialog;
import researchgrants.utils.WindowHelpers;

/**
 * The application's main menu frame.
 */
public class ResearchGrantsView extends FrameView {
    
    private LoggedDataPanelsListGrantOfficer loggedInGrantOfficer;
    
    /**
     * Constructs the main view (<code>SingleFrameApplication</code>) of the application.
     * @param app   the application
     */
    public ResearchGrantsView(SingleFrameApplication app) {
        super(app);

        initComponents();
        
        MyDialog.changeToTitleLabel(lblGeneralMenuCaption);
        MyDialog.changeToTitleLabel(lblPersonalizedMenuCaption);
        WindowHelpers.allowEscapeApplication(this);

        
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
        {
            loggedInGrantOfficer = new LoggedDataPanelsListGrantOfficer();
            GrantOfficerChangeListener grantOfficerChangeListener=new GrantOfficerChangeListener(loggedInGrantOfficer);
            loggedInGrantOfficer.addChangeListener(grantOfficerChangeListener);
            if (PropertyFile.getInstance().getLoggedInGrantOfficer()!=null) { 
                loggedInGrantOfficer.setSelected(PropertyFile.getInstance().getLoggedInGrantOfficer().getId());
            }
            pnlGrantOfficers.add(loggedInGrantOfficer.getEditComponent());
            grantOfficerChangeListener.stateChanged(new ChangeEvent(this));
            //            btnViewGrantRequestByGrantOfficer.setEnabled(false);
            btnSaveLoggedInGrantOfficer.addActionListener(new btnViewGrantRequestByGrantOfficerActionListener(this.getFrame(), loggedInGrantOfficer));
        }

        
        
        
        getFrame().pack();
    }

    /**
     * Shows the about box view of the application.
     */
    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = ResearchGrantsApp.getApplication().getMainFrame();
            aboutBox = new ResearchGrantsAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ResearchGrantsApp.getApplication().show(aboutBox);
    }

    /**
     * Loads the logged in <code>GrantOfficer</code>.
     * @return  the logged in grant officer. Null if none previously saved.
     */
    private GrantOfficer getLoggedInGrantOfficer() {
        return(GrantOfficer.fromListId(loggedInGrantOfficer.getEdittedValue()));
    }
    
    /**
     * Gets a list of all <code>GrantRequest</code>s (<code>GrantReqeustsList</code>) for the logged in <code>GrantOfficer</code>
     * @return a list of all GrantRequests for the Logged-in <code>GrantOfficer</code>
     */
    private GrantRequestsList getLoggedInGrantOfficerGrantRequests() {
        GrantRequestsList allGrantRequests = AllGrantRequests.getAllGrantRequests();
        Collection<GrantOfficer> grantOfficers=new ArrayList<GrantOfficer>(1);
        grantOfficers.add(getLoggedInGrantOfficer());
        GrantRequestsListFilters.filterByGrantOfficers(allGrantRequests, grantOfficers);
        return(allGrantRequests);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        lblGeneralMenuCaption = new javax.swing.JLabel();
        btnViewAllGrantRequests = new javax.swing.JButton();
        btnViewAllPis = new javax.swing.JButton();
        btnAddGrantRequest = new javax.swing.JButton();
        btnAddPi = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        lblPersonalizedMenuCaption = new javax.swing.JLabel();
        lblLoggedInGrantOfficerCaption = new javax.swing.JLabel();
        pnlGrantOfficers = new javax.swing.JPanel();
        btnSaveLoggedInGrantOfficer = new javax.swing.JButton();
        btnViewGrantRequestByStatusUnsubmitted = new javax.swing.JButton();
        btnViewGrantRequestByStatusSubmitted = new javax.swing.JButton();
        btnViewGrantRequestByStatusAwarded = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        lblGeneralMenuCaption.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(researchgrants.ResearchGrantsApp.class).getContext().getResourceMap(ResearchGrantsView.class);
        lblGeneralMenuCaption.setText(resourceMap.getString("lblGeneralMenuCaption.text")); // NOI18N
        lblGeneralMenuCaption.setName("lblGeneralMenuCaption"); // NOI18N

        btnViewAllGrantRequests.setText(resourceMap.getString("btnViewAllGrantRequests.text")); // NOI18N
        btnViewAllGrantRequests.setName("btnViewAllGrantRequests"); // NOI18N
        btnViewAllGrantRequests.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewAllGrantRequestsActionPerformed(evt);
            }
        });

        btnViewAllPis.setText(resourceMap.getString("btnViewAllPis.text")); // NOI18N
        btnViewAllPis.setName("btnViewAllPis"); // NOI18N
        btnViewAllPis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewAllPisActionPerformed(evt);
            }
        });

        btnAddGrantRequest.setText(resourceMap.getString("btnAddGrantRequest.text")); // NOI18N
        btnAddGrantRequest.setName("btnAddGrantRequest"); // NOI18N
        btnAddGrantRequest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddGrantRequestActionPerformed(evt);
            }
        });

        btnAddPi.setText(resourceMap.getString("btnAddPi.text")); // NOI18N
        btnAddPi.setName("btnAddPi"); // NOI18N
        btnAddPi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddPiActionPerformed(evt);
            }
        });

        jSeparator1.setName("jSeparator1"); // NOI18N

        lblPersonalizedMenuCaption.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblPersonalizedMenuCaption.setText(resourceMap.getString("lblPersonalizedMenuCaption.text")); // NOI18N
        lblPersonalizedMenuCaption.setName("lblPersonalizedMenuCaption"); // NOI18N

        lblLoggedInGrantOfficerCaption.setText(resourceMap.getString("lblLoggedInGrantOfficerCaption.text")); // NOI18N
        lblLoggedInGrantOfficerCaption.setName("lblLoggedInGrantOfficerCaption"); // NOI18N

        pnlGrantOfficers.setName("pnlGrantOfficers"); // NOI18N
        pnlGrantOfficers.setPreferredSize(new java.awt.Dimension(50, 100));
        pnlGrantOfficers.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

        btnSaveLoggedInGrantOfficer.setText(resourceMap.getString("btnSaveLoggedInGrantOfficer.text")); // NOI18N
        btnSaveLoggedInGrantOfficer.setName("btnSaveLoggedInGrantOfficer"); // NOI18N
        btnSaveLoggedInGrantOfficer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveLoggedInGrantOfficerActionPerformed(evt);
            }
        });

        btnViewGrantRequestByStatusUnsubmitted.setText(resourceMap.getString("btnViewGrantRequestByStatusUnsubmitted.text")); // NOI18N
        btnViewGrantRequestByStatusUnsubmitted.setName("btnViewGrantRequestByStatusUnsubmitted"); // NOI18N
        btnViewGrantRequestByStatusUnsubmitted.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewGrantRequestByStatusUnsubmittedActionPerformed(evt);
            }
        });

        btnViewGrantRequestByStatusSubmitted.setText(resourceMap.getString("btnViewGrantRequestByStatusSubmitted.text")); // NOI18N
        btnViewGrantRequestByStatusSubmitted.setName("btnViewGrantRequestByStatusSubmitted"); // NOI18N
        btnViewGrantRequestByStatusSubmitted.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewGrantRequestByStatusSubmittedActionPerformed(evt);
            }
        });

        btnViewGrantRequestByStatusAwarded.setText(resourceMap.getString("btnViewGrantRequestByStatusAwarded.text")); // NOI18N
        btnViewGrantRequestByStatusAwarded.setName("btnViewGrantRequestByStatusAwarded"); // NOI18N
        btnViewGrantRequestByStatusAwarded.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnViewGrantRequestByStatusAwardedActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblGeneralMenuCaption, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                    .addComponent(lblPersonalizedMenuCaption, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnViewAllGrantRequests, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                            .addComponent(btnViewAllPis, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnAddGrantRequest, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
                            .addComponent(btnAddPi, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(lblLoggedInGrantOfficerCaption)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnlGrantOfficers, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnSaveLoggedInGrantOfficer, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnViewGrantRequestByStatusAwarded, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                    .addComponent(btnViewGrantRequestByStatusSubmitted, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(btnViewGrantRequestByStatusUnsubmitted, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblGeneralMenuCaption)
                .addGap(11, 11, 11)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnViewAllGrantRequests)
                    .addComponent(btnAddGrantRequest))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnViewAllPis)
                    .addComponent(btnAddPi))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblPersonalizedMenuCaption)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblLoggedInGrantOfficerCaption, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pnlGrantOfficers, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(btnSaveLoggedInGrantOfficer)
                        .addGap(11, 11, 11)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnViewGrantRequestByStatusUnsubmitted)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnViewGrantRequestByStatusSubmitted)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnViewGrantRequestByStatusAwarded)
                .addGap(70, 70, 70))
        );

        mainPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnSaveLoggedInGrantOfficer, lblLoggedInGrantOfficerCaption, pnlGrantOfficers});

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(researchgrants.ResearchGrantsApp.class).getContext().getActionMap(ResearchGrantsView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 476, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

private void btnViewAllGrantRequestsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewAllGrantRequestsActionPerformed
    GrantRequestsList list=AllGrantRequests.getAllGrantRequests();
    list.show(this.getFrame(),"List of All Grant Requests");
}//GEN-LAST:event_btnViewAllGrantRequestsActionPerformed

private void btnViewAllPisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewAllPisActionPerformed
    PisList list=AllPis.getAllPis();
    list.show(this.getFrame(),"List of All Pis");
}//GEN-LAST:event_btnViewAllPisActionPerformed

private void btnAddGrantRequestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddGrantRequestActionPerformed
    AllGrantRequests.inputNewGrantRequest(this.getFrame());
}//GEN-LAST:event_btnAddGrantRequestActionPerformed

private void btnAddPiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddPiActionPerformed
    AllPis.inputNewPi(this.getFrame());
}//GEN-LAST:event_btnAddPiActionPerformed

private void btnSaveLoggedInGrantOfficerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveLoggedInGrantOfficerActionPerformed

}//GEN-LAST:event_btnSaveLoggedInGrantOfficerActionPerformed

private void btnViewGrantRequestByStatusSubmittedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewGrantRequestByStatusSubmittedActionPerformed
        GrantRequestsList allGrantRequests = getLoggedInGrantOfficerGrantRequests();
        GrantRequestsListFilters.filterByLastStatusChangeSubmitted(allGrantRequests);
        allGrantRequests.show(this.getFrame(), "Submitted Grant Requests");
}//GEN-LAST:event_btnViewGrantRequestByStatusSubmittedActionPerformed

private void btnViewGrantRequestByStatusAwardedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewGrantRequestByStatusAwardedActionPerformed
        GrantRequestsList allGrantRequests = getLoggedInGrantOfficerGrantRequests();
        GrantRequestsListFilters.filterByLastStatusChangeAwarded(allGrantRequests);
        allGrantRequests.show(this.getFrame(), "Awarded Grant Requests");
}//GEN-LAST:event_btnViewGrantRequestByStatusAwardedActionPerformed

private void btnViewGrantRequestByStatusUnsubmittedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewGrantRequestByStatusUnsubmittedActionPerformed
        GrantRequestsList allGrantRequests = getLoggedInGrantOfficerGrantRequests();
        GrantRequestsListFilters.filterByLastStatusChangeUnsubmitted(allGrantRequests);
        allGrantRequests.show(this.getFrame(), "Grant Requests in Development");
}//GEN-LAST:event_btnViewGrantRequestByStatusUnsubmittedActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddGrantRequest;
    private javax.swing.JButton btnAddPi;
    private javax.swing.JButton btnSaveLoggedInGrantOfficer;
    private javax.swing.JButton btnViewAllGrantRequests;
    private javax.swing.JButton btnViewAllPis;
    private javax.swing.JButton btnViewGrantRequestByStatusAwarded;
    private javax.swing.JButton btnViewGrantRequestByStatusSubmitted;
    private javax.swing.JButton btnViewGrantRequestByStatusUnsubmitted;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblGeneralMenuCaption;
    private javax.swing.JLabel lblLoggedInGrantOfficerCaption;
    private javax.swing.JLabel lblPersonalizedMenuCaption;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JPanel pnlGrantOfficers;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;

    private class GrantOfficerChangeListener implements ChangeListener {

       LoggedDataPanelsListGrantOfficer loggedDataPanelsListGrantOfficer;

        public GrantOfficerChangeListener(LoggedDataPanelsListGrantOfficer loggedDataPanelsListGrantOfficer) {
            this.loggedDataPanelsListGrantOfficer = loggedDataPanelsListGrantOfficer;
        }
        

        
        @Override
        public void stateChanged(ChangeEvent e) {
            btnSaveLoggedInGrantOfficer.setEnabled(!loggedDataPanelsListGrantOfficer.isEmpty());
            btnViewGrantRequestByStatusUnsubmitted.setEnabled(!loggedDataPanelsListGrantOfficer.isEmpty());
            btnViewGrantRequestByStatusSubmitted.setEnabled(!loggedDataPanelsListGrantOfficer.isEmpty());
            btnViewGrantRequestByStatusAwarded.setEnabled(!loggedDataPanelsListGrantOfficer.isEmpty());
            
        }
    }

    private static class btnViewGrantRequestByGrantOfficerActionListener implements ActionListener {

        LoggedDataPanelsListGrantOfficer loggedDataPanelsListGrantOfficer;
        Window parentWindow;

        public btnViewGrantRequestByGrantOfficerActionListener(Window parentWindow, LoggedDataPanelsListGrantOfficer loggedDataPanelsListGrantOfficer) {
            this.loggedDataPanelsListGrantOfficer = loggedDataPanelsListGrantOfficer;
            this.parentWindow=parentWindow;
        }

        public void actionPerformed(ActionEvent e) {
            String grantOfficerListId=loggedDataPanelsListGrantOfficer.getEdittedValue();
            if (grantOfficerListId.equals("")) {
                PropertyFile.getInstance().setLoggedInGrantOfficer(null);
            } else {
                GrantOfficer grantOfficer=GrantOfficer.fromListId(grantOfficerListId);
                PropertyFile.getInstance().setLoggedInGrantOfficer(grantOfficer);
            }
        }
    }



}
